package org.romzzz.gwtclassifieds.client.ui;

import org.romzzz.gwtclassifieds.client.i18n.LocalizedStrings;

import com.extjs.gxt.ui.client.Style;
import com.extjs.gxt.ui.client.widget.ContentPanel;
import com.extjs.gxt.ui.client.widget.Viewport;
import com.extjs.gxt.ui.client.widget.layout.BorderLayout;
import com.extjs.gxt.ui.client.widget.layout.BorderLayoutData;
import com.extjs.gxt.ui.client.widget.layout.FillLayout;
import com.google.gwt.core.client.GWT;

/**
 * This is the main screen that contains the layout for all the components.
 */
public class ClassifiedScreen extends Viewport {
	
	public ClassifiedScreen(boolean adminMode) {
		super();
		this.setLayout(new FillLayout());
		
		ClassifiedDetails classifiedDetails = new ClassifiedDetails();
		ClassifiedGrid classifiedGrid = new ClassifiedGrid();
		CategoryList categoryList = new CategoryList(adminMode);
		
		classifiedGrid.setCategoryList(categoryList);
		classifiedGrid.setClassifiedDetails(classifiedDetails);
		categoryList.setClassifiedGrid(classifiedGrid);
		
		ContentPanel globalContent = new ContentPanel(new BorderLayout());
		LocalizedStrings localizedStrings = GWT.create(LocalizedStrings.class);
		StringBuilder heading = new StringBuilder(localizedStrings.greetingTitle());
		if (adminMode) {
			heading.append(" ").append(localizedStrings.adminMode());
		}
		globalContent.setHeading(heading.toString());
		BorderLayoutData data = new BorderLayoutData(Style.LayoutRegion.WEST, 250);
		data.setSplit(true);
		data.setCollapsible(true);
		globalContent.add(categoryList, data);
		ContentPanel classifiedContent = new ContentPanel(new BorderLayout());
		classifiedContent.setHeaderVisible(false);
		data = new BorderLayoutData(Style.LayoutRegion.SOUTH, 200);
		data.setSplit(true);
		classifiedContent.add(classifiedDetails, data);
		classifiedContent.add(classifiedGrid, new BorderLayoutData(Style.LayoutRegion.CENTER));
		globalContent.add(classifiedContent, new BorderLayoutData(Style.LayoutRegion.CENTER));
		add(globalContent);
		
		categoryList.refresh();
	}

}
